<?php
//use common\Tools;
//use yii\web\Response;
//use yii\base\Event;

/*if ($_SERVER['REQUEST_METHOD'] === "OPTIONS") {
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Methods: *");
    header("Access-Control-Allow-Headers: *");
    header("Access-Control-Request-Headers: *");
//    header("Access-Control-Max-Age: 86400");
//    header("Access-Control-Expose-Headers: Content-Type, Content-Length, Authorization, Accept, X-Requested-With");
    exit("ok");
}*/

$config = [
    'defaultRoute' => 'route/api',
    'bootstrap' => [
        'contentNegotiator' => [
            'class' => 'yii\filters\ContentNegotiator',
            'formats' => [
                'application/json' => 'json',
                'application/xml' => 'xml',
            ],
            'languages' => [
                'zh-CN',
                'en',
            ],
        ]
    ],
    "components" => [
        'errorHandler' => [
            'class'=>'common\components\fast_api\ErrorHandler',
        ],
        'fastApi' => [
            'class' => 'common\components\fast_api\FastApi',
        ],
        "request" => [
            'class' => '\yii\web\Request',
            'enableCookieValidation' => false,
//            'parsers' => [
//                'application/json' => 'yii\web\JsonParser',
//                'text/json' => 'yii\web\JsonParser',
//            ],
//            "csrfParam" => "_csrf-" . APP_ID,
        ],
        "user" => [
            "class" => 'xcxApi\rewrites\User',
            "identityClass" => 'xcxApi\models\db\MpUser',
            "enableAutoLogin" => true,
            "identityCookie" => ["name" => "_identity-" . APP_ID, "httpOnly" => true],
        ],
        "session" => [
            "name" => "session-" . APP_ID,
        ],
//        'response' => [
//            'class' => Response::class,
//            //返回异常统一处理
//            'on '.Response::EVENT_BEFORE_SEND => function (Event $event) {
//                /** @var Response $sender */
//                $sender = $event->sender;
//                $sender->format = Response::FORMAT_JSON;
//                Yii::$app->response->headers->set('Access-Control-Allow-Origin', '*');
//            },
//        ],
    ],
    'modules' => [
        'guest' => 'xcxApi\modules\guest\GuestModule',
        'user' => 'xcxApi\modules\user\UserModule',
        'product' => 'xcxApi\modules\product\ProductModule',
    ],
    'as tokenCheck' => [
        'class' => 'xcxApi\behaviors\TokenCheck',
        'except' => [
            'site/*',
            'gii/*',
            'debug/*',
            'route/*',
            'guest/*',
//            'user/file/chuck-upload',
//            'user/profile/*',
        ],
    ],
    'params' => [],
];
return $config;
